package com.sifa.springcloud.controller;


import com.sifa.springcloud.entities.CommentResult;
import com.sifa.springcloud.entities.Payment;
import com.sifa.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;


    @PostMapping("/payment/create")
    public CommentResult createPayment(@RequestBody Payment payment){

        System.out.println("对了吗");
        int i = paymentService.create(payment);
        if (i>0){
            return new CommentResult(200,"插入数据库成功"+serverPort,null);
        }
        return new CommentResult(404,"插入失败",null);
    }
    @GetMapping("/payment/get/{id}")
    public CommentResult getPayment(@PathVariable("id")Integer id){
        Payment paymentById = paymentService.getPaymentById(id);
        if (paymentById!=null){
            return new CommentResult(0,"成功"+serverPort,paymentById);
        }
      else {
          return new CommentResult(0,"失败",null);
        }
    }
    @GetMapping("/payment/lb")
    public String getPaymentLB(){
        return serverPort;
    }
}
